package lagou.cn.homework

case class UserInfo(userName:String,location:String,startTime:Int,duration:Int)
object location {
  def main(args: Array[String]): Unit = {
    val userInfoList: List[UserInfo] = List(
      UserInfo("UserA", "LocationA", 8, 60),
      UserInfo("UserA", "LocationA", 9, 60),
      UserInfo("UserA", "LocationB", 10, 60),
      UserInfo("UserA", "LocationB", 11, 80)
    )

    val userMap: Map[String, List[UserInfo]] = userInfoList.groupBy(
      t => t.userName + "," + t.location
    )

    val orderByUserMap: Map[String, List[UserInfo]] = userMap.mapValues(
      t => t.sortBy(x => x.startTime)
    )

    var firstTime = 0

    val totalMap = orderByUserMap.mapValues(
      t => {
        val firstTime: Int = t.head.startTime
        val sum: Int = t.map(x => x.duration).sum
        sum
      }
    )

    totalMap.foreach{
      case (datas,sumTime) => println(s"datas,$firstTime,$sumTime")
    }
  }
}
